import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { CareerConfig } from "../../resource/CareerConfig";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { Cache } from "../../cache/Cache";
import { PlayerOpRegister } from "../common/menu/PlayerOpRegister";
import { PlayerOpMenuConst } from "../common/menu/PlayerOpMenuConst";
import { DataEvent } from "../../events/DataEvent";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { GButton } from "../../../../com/mui/controls/GButton";
//class GroupPlayersCellRenderer
    
    export  class GroupPlayersCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            var loc1=GlobalClass.getScaleBitmap("Friend_over", new Object /* flash.geom.Rectangle */(85, 5, 4, 10));
            loc1.width = 260;
            loc1.height = 38;
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", loc1);
            this.setStyle("overSkin", loc1);
            this.setStyle("selectedDownSkin", loc1);
            this.setStyle("selectedOverSkin", loc1);
            this.setStyle("selectedUpSkin", loc1);
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=ResouceConst.getScaleBitmap("SplitLine");
            loc1.width = 260;
            this.addChild(loc1);
            this._captainIcon = GlobalClass.getBitmap(ImagesConst.GroupCaptainIcon);
            this._captainIcon.x = 13;
            this._captainIcon.y = 10;
            this.addChild(this._captainIcon);
            this.nameLabel = new GLabel();
            addChild(this.nameLabel);
            this.nameLabel.setSize(98, 22);
            this.nameLabel.x = 30;
            this.nameLabel.y = 9;
            this.nameLabel.mouseEnabled = false;
            this.levelLabel = new GLabel();
            addChild(this.levelLabel);
            this.levelLabel.setSize(30, 22);
            this.levelLabel.x = 110;
            this.levelLabel.y = 9;
            this.levelLabel.mouseEnabled = false;
            this.campLabel = new GLabel();
            addChild(this.campLabel);
            this.campLabel.setSize(30, 22);
            this.campLabel.x = 146;
            this.campLabel.y = 9;
            this.campLabel.mouseEnabled = false;
            this.careerLabel = new GLabel();
            addChild(this.careerLabel);
            this.careerLabel.setSize(76, 22);
            this.careerLabel.x = 177;
            this.careerLabel.y = 9;
            this.careerLabel.mouseEnabled = false;
            this._operMenuSprite = new Object /* flash.display.Sprite */();
            this._operMenuSprite.buttonMode = true;
            this._operMenuSprite.graphics.beginFill(16711680, 0);
            this._operMenuSprite.graphics.drawRect(0, 0, 200, 38);
            this._operMenuSprite.cacheAsBitmap = true;
            this.addChild(this._operMenuSprite);
            this.kickOutBtn = ObjCreate.createGButton(Language.getString(62038), 205, 8, 49, 22, this, "ButtonMini");
            this.kickOutBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this.kickOutBtn.drawNow();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            super.data = arg1;
            if (arg1) 
            {
                this._isCrossGroup = arg1["isCrossGroup"];
                loc1 = arg1["player"] as SPublicMiniPlayer;
                this.nameLabel.htmlText = HTMLUtil.addColor(loc1.name, "#B1EFFE");
                this.levelLabel.htmlText = HTMLUtil.addColor(loc1.level + "", "#B1EFFE");
                this.campLabel.htmlText = HTMLUtil.addColor(GameDefConfig.instance.getCampShort(loc1.camp).name, ColorConfig.instance.getCampColor(loc1.camp).color);
                loc2 = loc1.careerEnable != 0 ? loc1.careerEnable : loc1.career;
                if (CareerConfig.instance.getInfoByCode(loc2)) 
                {
                    this.careerLabel.htmlText = HTMLUtil.addColor(CareerConfig.instance.getInfoByCode(loc2).name, "#B1EFFE");
                }
                if (data.isCaption) 
                {
                    this._captainIcon.visible = true;
                }
                else 
                {
                    this._captainIcon.visible = false;
                }
                loc3 = new PlayerMiniInfo(loc1);
                if (EntityUtil.equal(Cache.instance.role.entityInfo.entityId, loc1.entityId)) 
                {
                    PlayerOpRegister.Register(this._operMenuSprite, loc3, PlayerOpMenuConst.RoleMemOpMenu);
                    this.kickOutBtn.visible = true;
                    this.kickOutBtn.label = Language.getString(62039);
                }
                else if (!this._isCrossGroup && EntityUtil.equal(Cache.instance.role.entityInfo.entityId, Cache.instance.group.captain) || this._isCrossGroup && EntityUtil.equal(Cache.instance.role.entityInfo.entityId, Cache.instance.crossGroup.captain)) 
                {
                    PlayerOpRegister.Register(this._operMenuSprite, loc3, PlayerOpMenuConst.GroupCaptainOpMenu);
                    this.kickOutBtn.visible = true;
                    this.kickOutBtn.label = Language.getString(62038);
                }
                else 
                {
                    PlayerOpRegister.Register(this._operMenuSprite, loc3, PlayerOpMenuConst.GroupMemOpMenu);
                    this.kickOutBtn.visible = false;
                }
            }
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (data) 
            {
                loc1 = data["player"] as SPublicMiniPlayer;
                if (EntityUtil.equal(Cache.instance.role.entityInfo.entityId, loc1.entityId)) 
                {
                    if (this._isCrossGroup) 
                    {
                        this.dispatchEvent(new DataEvent(GModuleEvent.Event_CrossLeaveGroup, null, false, true, false));
                    }
                    else 
                    {
                        this.dispatchEvent(new DataEvent(GModuleEvent.Event_LeaveGroup, null, false, true, false));
                    }
                }
                else if (this._isCrossGroup) 
                {
                    this.dispatchEvent(new DataEvent(GModuleEvent.Event_CrossKickOut, loc1.entityId, false, true, false));
                }
                else 
                {
                    this.dispatchEvent(new DataEvent(GModuleEvent.Event_KickOut, loc1.entityId, false, true, false));
                }
            }
            return;
        }

        /* internal */ /* var */_headImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_captainIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */nameLabel: GLabel;

        /* internal */ /* var */levelLabel: GLabel;

        /* internal */ /* var */campLabel: GLabel;

        /* internal */ /* var */careerLabel: GLabel;

        /* internal */ /* var */_operMenuSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */kickOutBtn: GButton;

        /* internal */ /* var */inviteBtn: GButton;

        /* internal */ /* var */_isCrossGroup: Boolean;
    }
